/**
 *  JSimProd - Java simulation code for production processes
 *  Copyleft Jorge Mira Yagüe <jorge.mira.yague@gmail.com>
 *  Universidad de Alicante 2009
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package lib.simul;

import java.util.Calendar;
import lib.plan.Item;
import lib.xml.XMLizable;

/**
 * An event is the representation o something that happens on the factory, every
 * event has a date when it happens, a type which determines what kind of event
 * it is, the station where the event happens and the associated item to it.
 * @see Item
 * @see EventType
 * @author Jorge Mira Yagüe
 */
public class Event implements XMLizable {

    private Calendar calendar;
    private EventType type;
    private Item item;
    private String stationName;

    /**
     * Builds an event with the parameters given
     * @param calendar the date when the event happens
     * @param type the type of the event
     * @param item the item over the event happens
     * @param stationName the name of the station where the event happens
     * @see EventType
     */
    public Event(Calendar calendar,
            EventType type,
            Item item,
            String stationName) {
        this.calendar = calendar;
        this.type = type;
        this.item = item;
        this.stationName = stationName;
    }

    public Calendar getCalendar() {
        return calendar;
    }

    public String getStationName() {
        return stationName;
    }

    public EventType getType() {
        return type;
    }

    public Item getItem() {
        return item;
    }

    public String toXML() {
        String result = "<Event ";
        result += "date=\"" + calendar.getTimeInMillis() + "\" ";
        result += "type=\"" + type + "\" ";
        result += "itemOrder=\"" + item.getOrder() + "\" ";
        result += "itemNumber=\"" + item.getNumber() + "\" ";
        result += "stationName=\"" + stationName + "\" ";
        result += "/>\n";
        return result;
    }
}
